package com.bugslog.api.base;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bugslog.framework.web.api.ApiController;
import com.bugslog.framework.web.api.ApiException;
import com.bugslog.framework.web.api.ApiResponse;

/**
 * 
 * <b><code>TheApiController</code></b>
 * <p>
 * 父类
 * </p>
 * <b>Creation Time:</b> 2017年2月15日 下午3:23:20
 * @author 肥魔
 * @since infolab
 */
public class TheApi extends ApiController {
	final static Logger logger = LoggerFactory.getLogger(TheApi.class);
	private TheApiSession session = null;


	@Override
    public void validApi(HttpServletRequest request, String body) throws ApiException {
		
    }

    @Override
    public void initSession(HttpServletRequest request, String body) {
    	

    }
    
    /**
     * 获取当前线程的session对象
     * 
     *
     * @return
     * @since infolab
     */
    public TheApiSession getSession(){
    	return (TheApiSession) this.getRequest().getSession(true).getAttribute("session");
    }

    @Override
    public boolean hasSession() {
    	TheApiSession session = this.getSession();
		if(session != null){
			return true;
		}
		return false;
    }
    
    public void setSession(TheApiSession session){
    	this.getRequest().getSession(true).setAttribute("session", session);
		this.session = session;
    }

	@Override
	public Object onException(Exception e) {
		return ApiResponse.error(super.parseExceptionMessage(e));
	}

}
